// https://zhuanlan.zhihu.com/p/20139834



// 注意这里的 `target` 是 `Dog.prototype`
function readonly(target, key, descriptor) {
    // console.log(target,key,descriptor);
    descriptor.writable = false;
    return descriptor;
}


// 日志装饰器

function log(msg) {
    return function(target, key, descriptor){
        // 将原来的函数体保存起来
        let value = descriptor.value;
        console.log(msg);
        value();
    }
}


class Dog {
    constructor(props) {
        this.name = props.name;
        this.gender = props.gender;
    }
    // 只读装饰器
    @readonly
    static version='v-1.1.1';

    @log('调用了bark方法')
    bark() {
        return 'wang!wang!'
    }
    sayHi = () => {
        console.log('sayHi');
    }

}

let dog = new Dog({ name: 'Iris', gender: 'girl' });
dog.bark();
// Dog.version='Iris';
// 由于装饰器readonly修改了该bark属性, 所以brak属性是只读属性; 无法被重新赋值
// dog.bark = 'bark!bark!';
// dog.name="homie"
// console.log(dog);

export default Dog;